package ua.edu.nuos.jeetraining2012.cms.ui;

import com.vaadin.annotations.Theme;
import com.vaadin.cdi.CDIUI;
import com.vaadin.cdi.URLMapping;
import com.vaadin.navigator.Navigator;
import com.vaadin.server.VaadinRequest;
import com.vaadin.ui.UI;
import ua.edu.nuos.jeetraining2012.cms.service.User;
import ua.edu.nuos.jeetraining2012.cms.ui.views.CoursesView;
import ua.edu.nuos.jeetraining2012.cms.ui.views.LoginView;

import javax.ejb.EJB;

/**
 * The Application's "main" class
 */
@SuppressWarnings("serial")
@CDIUI
@URLMapping("/ui/*")
@Theme("custom")
public class MyVaadinUI extends UI {
    @EJB
    User user;

    Navigator navigator;

    private CoursesView courses;

    private LoginView loginView;

    @Override
    protected void init(VaadinRequest request) {
        navigator = new Navigator(this, this);
        courses = new CoursesView(navigator);
        navigator.addView("", courses);
        loginView = new LoginView();
        navigator.addView("loginView", loginView);


        String user = (String) getSession().getAttribute("user");
        if (user != null && !user.isEmpty()) {
            navigator.navigateTo("");
        }
        navigator.navigateTo("loginView");

    }
}
